/**
 * Copyright 2013 Mr.Hai Mobile Developer. All rights reserved.
 * HAI PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.hector.meinewerk.common;

import android.app.Application;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;

import com.hector.meinewerk.constants.Constants;
import com.hector.meinewerk.utils.GlobalUtils;
import com.hector.meinewerk.utils.StringUtil;

/**
 * 
 * application for app
 * 
 * @author: HaiTC3
 * @version: 1.1
 * @since: 1.0 | Mar 7, 2013
 */
public class GlobalInfo extends Application {
	public final String VERSION = "1.1";
	Context appContext;// application context
	Context activityContext;// activity context
	private static GlobalInfo instance = null;
	private boolean isAppActive;
	public BaseActivity lastShowActivity = null;
	// bien dung de debug
	public static final boolean ISDEBUG = false;
	// phan luu xuong file
	private Profile profile = new Profile();
	private Handler mHandler = new Handler();
	private Bitmap bmpData = null;// luu giu data bitmap khi dinh kem hinh anh

	// Methods
	public GlobalInfo() {
		super();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Application#onCreate()
	 */
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();

	}

	/**
	 * 
	 * get instance global info
	 * 
	 * @param @return
	 * @return: GlobalInfo
	 * @author: HaiTC3
	 * @date: Mar 6, 2013
	 */
	public static GlobalInfo getInstance() {
		if (instance == null) {
			instance = new GlobalInfo();
		}
		return instance;
	}

	/**
	 * 
	 * get PlatForm
	 * 
	 * @param @return
	 * @return: String
	 * @author: HaiTC3
	 * @date: Mar 6, 2013
	 */
	public String getPlatForm() {
		return Constants.STR_ANDROID;
	}

	/**
	 * 
	 * set bitmap data
	 * 
	 * @param @param data
	 * @return: void
	 * @author: HaiTC3
	 * @date: Mar 6, 2013
	 */
	public void setBitmapData(Bitmap data) {
		bmpData = data;
	}

	/**
	 * 
	 * getBitmapData
	 * 
	 * @param @return
	 * @return: Bitmap
	 * @author: HaiTC3
	 * @date: Mar 6, 2013
	 */
	public Bitmap getBitmapData() {
		return bmpData;
	}

	/**
	 * 
	 * huy bo doi tuong bitmap dta
	 * 
	 * @param
	 * @return: void
	 * @author: HaiTC3
	 * @date: Mar 6, 2013
	 */
	public void recycleBitmapData() {
		if (bmpData != null) {
			bmpData.recycle();
			bmpData = null;
		}
	}

	/**
	 * 
	 * Lay thong tin profile
	 * 
	 * @param @return
	 * @return: Profile
	 * @author: HaiTC3
	 * @date: Mar 6, 2013
	 */
	public Profile getProfile() {
		Object temp;
		if (profile == null || profile.getUserData() == null
				|| StringUtil.isNullOrEmpty(profile.getUserData().strUserName)) {
			if ((temp = GlobalUtils.readObject(Profile.APP_PROFILE)) != null) {
				profile = (Profile) temp;// bi out memory
				System.setProperty("networkaddress.cache.ttl", "0");
				System.setProperty("networkaddress.cache.negative.ttl", "0");
			}
		}
		return profile;
	}

	/**
	 * 
	 * set app context
	 * 
	 * @param @param context
	 * @return: void
	 * @author: HaiTC3
	 * @date: Mar 6, 2013
	 */
	public void setAppContext(Context context) {
		this.appContext = context;

	}

	/**
	 * 
	 * get app context
	 * 
	 * @param @return
	 * @return: Context
	 * @author: HaiTC3
	 * @date: Mar 6, 2013
	 */
	public Context getAppContext() {
		if (appContext == null) {
			appContext = new GlobalInfo();
		}
		return appContext;
	}

	/**
	 * 
	 * set activity context
	 * 
	 * @param @param context
	 * @return: void
	 * @author: HaiTC3
	 * @date: Mar 6, 2013
	 */
	public void setActivityContext(Context context) {
		this.activityContext = context;

	}

	/**
	 * 
	 * get activity context
	 * 
	 * @param @return
	 * @return: Context
	 * @author: HaiTC3
	 * @date: Mar 6, 2013
	 */
	public Context getActivityContext() {
		return activityContext;
	}

	/**
	 * 
	 * set app active
	 * 
	 * @param @param isActive
	 * @return: void
	 * @author: HaiTC3
	 * @date: Mar 6, 2013
	 */
	public void setAppActive(boolean isActive) {

		this.isAppActive = isActive;
	}

	/**
	 * 
	 * get app handler
	 * 
	 * @param @return
	 * @return: Handler
	 * @author: HaiTC3
	 * @date: Mar 6, 2013
	 */
	public Handler getAppHandler() {
		return mHandler;
	}

	/**
	 * 
	 * get app active
	 * 
	 * @param @return
	 * @return: boolean
	 * @author: HaiTC3
	 * @date: Mar 6, 2013
	 */
	public boolean isAppActive() {

		return isAppActive;
	}
}
